package org.arroganz.kapa.framework;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;

import org.arroganz.kapa.abstracts.AbstractFrame;
import org.arroganz.kapa.resources.Descriptions;
import org.arroganz.kapa.resources.Dimensions;
import org.arroganz.kapa.resources.R;

public class FrameMain extends AbstractFrame {

	private String title = R.getDescription(Descriptions.TITLE) + " " + R.getDescription(Descriptions.VERSION);
	private int width = R.getDimension(Dimensions.WIDTH);
	private int height = R.getDimension(Dimensions.HEIGHT);
	
	
	// Preferred Size of the Center Object via Click editable for Create LZD Monitor and small for Desktop editing
	
	// rects
	private Rectangle[] rectsY = new Rectangle[30];
	private Rectangle[] rectsTimeline = new Rectangle[30];
	private Rectangle[] rectsCenter = new Rectangle[13];
	
	// scrollPanes
	private JScrollPane scrollPaneVertical;
	private JScrollPane scrollPaneHorizontal;
	
	// canvas
	private JPanel myCanvasY = new MyCanvas();
	private JPanel myCanvasTimeline = new MyCanvas();
	private JPanel myCanvasCenter = new MyCanvas();
	
	public FrameMain(){
		
		this.setLayout(new BorderLayout());
		
		myCanvasY.setPreferredSize(new Dimension(5000, 5000)); // set PrefferedSize by getting the X and Y Items and Calculate the witdh and the Height
		
		int vScrollVertical = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
		int hScrollVertical = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
		scrollPaneVertical = new JScrollPane(myCanvasY, vScrollVertical, hScrollVertical);
		scrollPaneVertical.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener(){
			
			@Override
			public void adjustmentValueChanged(AdjustmentEvent e) {
				refresh();
			}
		});
		this.add(scrollPaneVertical, BorderLayout.CENTER);

		super.buildFrame(title, width, height); // Title should go to properties
		this.refresh();
	}
	
	public void refresh(){
		myCanvasY.repaint();
		this.repaint();
	}
	
	
}
